The Geometric Properties of Shape Objects
Every shape object has three geometric properties: the shape type, the shape geometry, and the shape fill. For geometric shapes, these properties define
The next three sections examine these properties in more detail.
- the type of shape--for example, a point, a line, or a curve
- the coordinates of the shape--for example, the position where a line starts and ends, or the positions of the corners of a rectangle
- how the shape is filled--for example, whether the shape is framed (drawn as an outline) or solid (drawn as a solid area)
Shape Type
The shape type property of a shape object specifies what type of shape the shape object represents. There are thirteen different QuickDraw GX shape types: one for bitmap shapes, one for picture shapes, three for typographic shapes, and eight for geometric shapes. The eight geometric shape types are:
The value of the shape type property affects the way QuickDraw GX interprets the other properties of the shape. In particular, different types of shapes store substantially different information in their geometry properties. For example, the geometry of a point shape contains only an x-coordinate and a y-coordinate. The geometry of a line contains an x-coordinate and a y-coordinate to define the beginning of the line and an x-coordinate and a y-coordinate to define the end of the line. The geometry of a polygon shape can contain many pairs of (x, y) coordinates.
- point
- line
- curve
- rectangle
- polygon
- path
- empty
- full
Figure 2-2 shows a shape object and lists six possible values for its shape type property. This figure also shows a sample geometry for each of the shape types listed. Each geometry is made up of geometric points (specified by (x, y) coordinate pairs) and edges connecting the geometric points. The next section, "Shape Geometry," discusses geometric points and edges in more detail.
Figure 2-2 The geometric shape types and examples of geometric shape geometries
There are two types of geometric shapes not shown in this figure: the empty shape and the full shape. An empty shape is a shape that has no geometry and covers no area. A full shape is the inverse of an empty shape--it covers all area. You can find more information about these shape types in "Empty Shapes and Full Shapes" beginning on page 2-16.
Shape Geometry
Each type of geometric shape uses the geometry property of its shape object in a slightly different manner. For example, empty shapes and full shapes store no information in their geometry, because they require no further geometric information--their shape type says it all.However, for other types of geometric shapes, the shape type does not contain all the geometric information necessary to define the shape. The geometries of these shapes contain (x, y) coordinate pairs called geometric points--points that specify the location, dimension, and form of the geometric shapes:
Figure 2-3 shows a polygon shape with a two polygon contours made up of seven geometric points total. This figure shows two views of the polygon geometry: as a list of (x, y) coordinate pairs and as seven geometric points plotted on a geometric grid. This second way of viewing geometries is used frequently throughout this book, as it shows not only the geometric points, but also the implied edges that connect them. Typically, the figures in this book do not show the grid, but just the points and edges.
- Point geometries contain one geometric point--an x-coordinate and a y-coordinate--to specify the position of the point shape. See "Point Shapes" on page 2-16 for more information.
- Line geometries contain two geometric points--one point to specify where the line starts and one to specify where the line ends. See "Line Shapes" on page 2-17 for more information.
- Rectangle geometries also contain two geometric points--specifying the positions of opposing corners of the rectangle. See "Rectangle Shapes" on page 2-20 for more information.
- Curve shapes store three geometric points in their geometry--one to specify where the curve starts, another to specify where the curve ends, and another, called the off-curve control point, to specify the tangents used to define the curve. See "Curve Shapes" on page 2-18 for more information.
- A polygon shape can contain multiple contours. A polygon contour is a series of geometric points connected by straight lines--for example, a V-shape, a triangle, or a hexagon.
- A path geometry can also contain multiple contours, but each path contour can contain curves as well as straight lines.
Figure 2-3 A polygon shape with a single contour containing three geometric points
Each geometric point in a geometry has a geometry index--if you consider the geometry as a list of geometric points starting from the first geometric point of the first contour to the last geometric point of the last contour, the geometry index of a particular geometric point is its position in this list. For example, in the shape in Figure 2-3, the first point (0.0, 100.0) has a geometry index of 1, the second point (50.0, 0.0) has a geometry index of 2, and the third point (100.0, 100.0) has a geometry index of 3. The first point in the second contour (0.0, 150.0) has a geometry index of 4, as it is the fourth geometric point in the geometry. However, it has a contour index of 1, as it is the first point of its contour. Similarly, the next point (100.0, 150.0) has a geometry index of 5 and a contour index of 2, and so forth.
Notice that each of the three edges of the polygon contour in Figure 2-3 has a direction. The first edge is pointing up and to the right; the second edge is pointing down and to the right; the third edge is pointing to the left. QuickDraw GX takes into consideration the direction that an edge is pointing in a number of circumstances:
QuickDraw GX uses contour direction and the inside and outside of a shape when applying certain stylistic variations, as described in Chapter 3, "Geometric Styles," and when performing certain geometric operations, as described in Chapter 4, "Geometric Operations," of this book.
- When filling a shape. QuickDraw GX allows you to choose how a shape should be filled. The next section, "Shape Fill," discusses how the direction of an edge can affect how QuickDraw GX fills a shape.
- When determining the contour direction of a contour. In the example in Figure 2-3, both polygon contours have a clockwise contour direction. If their geometric points were reversed, the polygon contours would have a counterclockwise contour direction.
- When determining the inside or outside of a contour. QuickDraw GX normally defines the right side of an edge to be the inside and the left side to be the outside. Since the example in Figure 2-3 has a clockwise contour direction, the inside of the contour corresponds to what you would expect the inside to be. If the contour had a counterclockwise direction, the inside of the contour would correspond to what you might expect the outside to be.
For more details about the geometries of the various geometric shapes, see "The Geometric Shape Types" beginning on page 2-16.
Shape Fill
The shape fill property specifies how QuickDraw GX interprets the geometric points of a geometric shape's geometry during drawing and other operations. There are two basic types of shape fills:
Figure 2-4 shows an example of a polygon contour similar to the one in Figure 2-3, and how QuickDraw GX might draw it with a framed fill and with a solid fill.
- Framed fills. These shape fills indicate that QuickDraw GX should interpret the shape as an outline--as a series of edges.
- Solid fills. These shape fills indicate that QuickDraw GX should interpret the shape as a solid area--the edges of the shape represent the boundaries of the area.
Figure 2-4 Framed shapes versus solid shapes
QuickDraw GX actually provides seven types of shape fills:
Figure 2-5 shows these shape fills and the effect they have on three sample geometries.
- no-fill shape fill
- open-frame shape fill (also called frame fill)
- closed-frame shape fill (also called hollow fill)
- even-odd shape fill (also called solid fill)
- winding shape fill
- inverse even-odd shape fill (also called inverse fill and inverse solid fill)
- inverse winding shape fill
Figure 2-5 The various shape fills and examples of their effects
The no-fill shape fill specifies that QuickDraw GX should not draw the shape. You can use this shape fill to hide a shape. You can specify the no-fill shape fill for any shape type.
The open-frame shape fill specifies that QuickDraw GX should draw a shape as a connected set of edges. The closed-frame shape fill indicates that QuickDraw GX should also connect the last geometric point of a contour to the first geometric point of that contour.
The even-odd shape fill and the winding shape fill indicate that QuickDraw GX should interpret the shape as a solid area--the edges of the shape represent the boundaries of the area. These two shape fills differ in the algorithm they use to determine what area to include in the shape.
The even-odd shape fill indicates that QuickDraw GX should use the even-odd rule to determine what area lies inside a shape. As QuickDraw GX scans a shape horizontally, it fills the area between every other pair of edges, as shown in Figure 2-6.
The winding shape fill indicates that QuickDraw GX should use the winding-number rule to determine what area lies inside a shape. As QuickDraw GX scans a shape horizontally, it increments a counter the first time it crosses an edge of the shape. It also notices whether the contour was directed up or down at that edge. As QuickDraw GX continues to scan the shape horizontally, everytime it crosses another edge pointed in the same direction (up or down), it increments the counter, and when it crosses an edge pointing in the opposite direction (down or up), it decrements the counter. Wherever along the horizontal scan line the counter is not zero, QuickDraw GX fills the area, as is shown in Figure 2-6.
Figure 2-6 The even-odd rule and winding-number rule algorithms
The inverse even-odd shape fill indicates the inverse of the even-odd shape fill, as shown in Figure 2-7.
Figure 2-7 The inverse even-odd shape fill
Similarly, the inverse winding shape fill indicates the inverse of the winding shape fill.
Not all shape fills are appropriate for all types of geometric shapes. For example, a rectangle shape can have a closed-frame shape fill but not an open-frame shape fill; a line shape can only have an no-fill or an open-frame shape fill.
See the sections on each shape type, beginning on page 2-16, for a complete discussion of the shape fills that are allowed for each shape type.
The shape fill does more than affect the way a shape is drawn; it affects the fundamental behavior of a shape. Two shapes with the same geometry that have different shape fills can exhibit vastly different geometric behaviors. For example, the shape fill can affect
For examples of how shape fill affects the behavior of shapes, see
- stylistic variations, which are described in Chapter 3, "Geometric Styles," in this book
- shape measurements and other geometric operations, which are discussed in Chapter 4, "Geometric Operations," in this book (As an example, a polygon with the closed-frame shape fill might simplify to a rectangle. However, the same polygon with the open-frame fill might not simplify at all.)
- hit-testing, which is described in the chapter "Transform Objects" and the chapter "Shape Objects" in Inside Macintosh: QuickDraw GX Objects
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help